<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">
        <style>
			.choose{
				width: 190px;
				margin-right: 45px;
			}
		</style>
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form test_edit" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div style="display: flex;align-items: center;">
								<div class="layui-form-item">
									<label class="layui-form-label">选择会员：</label>
									<div class="layui-input-block" style="display: flex;align-items: center;">
										<input type="text" name="copartner_memberid" placeholder="选择会员" autocomplete="off" class="layui-input choose">
										<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="searchdata('copartner_memberid')">选择</button>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">合伙人类型</label>
									<div class="layui-input-block">
										<select name="type" lay-verify="required" lay-filter="select1" id="select1">
											<option value=""></option>
											<option value="1">天使合伙人</option>
											<option value="2">业务合伙人</option>
											<option value="3">事业合伙人</option>
											<!-- <option value="4">城市合伙人</option> -->
										</select>
									</div>
								 </div>
							</div>

							
							<!-- <div class="layui-form-item">
								<label class="layui-form-label">订单状态：</label>
								<div class="layui-input-block">
									<select name="status" lay-verify="required">
										<option value=""></option>
										<option value="1">待划拨</option>
										<option value="2">划拨中</option>
										<option value="3">划拨完成</option>
									</select>
								</div>
							</div> -->
							<div class="layui-form-item">
								<label class="layui-form-label">支付金额：</label>
								<div class="layui-input-block">
									<input type="text" name="pay_price" placeholder="请输入支付金额" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">支付方式：</label>
								<div class="layui-input-block">
									<div class="payment"></div>
								</div>
							</div>
							<div class="layui-form-item ">
								<label class="layui-form-label">支付状态：</label>
								<div class="layui-input-block">
									<input type="radio" name="status_pay" value="1" title="待支付">
									<!--<input type="radio" name="status" value="0" title="待审核">-->
									<input type="radio" name="status_pay" value="2" title="已支付" >
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">支付时间：</label>
								<div class="layui-input-inline">
									<!-- readonly -->
									<input type="text" name="pay_time" class="layui-input" id="pay_time" autocomplete="off" 
										placeholder="支付时间" >
									 <i class="layui-icon layui-icon-disabled" style="font-size: 30px; color: #1E9FFF;"></i> 
								</div>
							</div>
							
							<!-- <div class="layui-form-item">
								<label class="layui-form-label">单价：</label>
								<div class="layui-input-block">
									<input type="text" name="price" lay-verify="required" placeholder="单价" autocomplete="off" class="layui-input" readonly>
								</div>
							</div> -->
								<div class="layui-form-item">
									<label class="layui-form-label">购买数量：</label>
									<div class="layui-input-inline">
										<input type="text" name="quantity" lay-verify="required" placeholder="购买数量
	" autocomplete="off" class="layui-input" >
									</div>
									
									<label class="layui-form-label">订单金额：</label>
									<div class="layui-input-inline">
										<input type="text" name="amount" placeholder="请输入订单金额" autocomplete="off" class="layui-input">
									</div>
								</div>
							
							
							
							
							<div class="layui-form-item">
								<label class="layui-form-label">开始日期：</label>
								<div class="layui-input-inline">
									<!-- readonly -->
									<input type="text" name="starttime" class="layui-input" id="starttime" autocomplete="off" 
										placeholder="开始日期：" >
									 <i class="layui-icon layui-icon-disabled" style="font-size: 30px; color: #1E9FFF;"></i> 
								</div>
								<label class="layui-form-label">结束时间：</label>
								<div class="layui-input-inline">
									<input type="text" name="endtime" class="layui-input" id="endtime"
										autocomplete="off" placeholder="结束时间：" >
										 <i class="layui-icon layui-icon-bluetooth" style="font-size: 30px; color: #1E9FFF;"></i> 
								</div>
							
								<!-- <label class="layui-form-label" style="width: 100px;">有效期年：</label> -->
							<!-- 	<div class="layui-input-inline">
									<div style="display: flex; align-items: center;">
										
								<button type="button"  class="layui-btn minus-btn layui-btn-sm" style="background-color: #38aaff;height: 36px;">
									    <i class="layui-icon layui-icon-subtraction"></i>
									  </button>
									<input type="text" name="validity_year" class="layui-input" readonly id="validity_year"
										autocomplete="off" placeholder="有效期年" style="text-align: center;">
										<button type="button"  class="layui-btn add-btn  layui-btn-sm"  style="background-color: #38aaff;height: 36px;">
										    <i class="layui-icon layui-icon-add-1"></i>
										  </button>
										  </div>
								</div> -->
							</div>
							
						
							 <div class="layui-form-item layui-form-text">
							    <label class="layui-form-label">备注</label>
							    <div class="layui-input-block">
							      <textarea name="notes" placeholder="备注" class="layui-textarea"></textarea>
							    </div>
							  </div>
						</div>
					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				id:getParam('id')
			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit','rate'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					form = layui.form;
					var rate = layui.rate;
					 //渲染
    				var ins1 = rate.render({
      					elem: '#score', //绑定元素
      					half:true,
 						value:_data.score,
						choose: function(value){
    						_data.score = value;
  						}
    				});
				sex_show('radio');
				payment_show('radio')
				service_type_show('checkbox');
				//日期时间选择器
				laydate.render({
					elem: '#starttime',
					type: 'date',
					done: function(value, date) {
						console.log("accountExpireTime:"+value)
						var startDate = new Date(value).getTime();
						var endTime = new Date( layui.jquery('#endtime').val()).getTime();
						if (endTime < startDate) {
							layer.msg("开始时间不能大于结束时间!")
							$('input[name=endtime]').val()
						}
					}
				
				});
				
				// 日期时间选择器
				laydate.render({
					elem: '#endtime',
					type: 'date',
					done: function(value, date) {
						console.log("accountExpireTime:"+value)
						var startDate = new Date( layui.jquery('#starttime').val()).getTime();
						var endTime = new Date(value).getTime();
						if (endTime < startDate) {
							$('input[name=endtime]').val()
							layer.msg("开始时间不能大于结束时间!")
						}
					}
				});
				
				// 日期时间选择器
				laydate.render({
					elem: '#pay_time',
					type: 'datetime'
				});
				
				// 创建一个 Date 对象
				var today = new Date();
				 
				// 获取年、月、日、时、分、秒
				var year = today.getFullYear();
				var month = today.getMonth() + 1; // 月份是从 0 开始计数的，需要加1
				var day = today.getDate();

				$("input[name=amount]").on("input",function(e){
				    //获取input输入的值
					var count=$('input[name=quantity]').val()
					var money=e.delegateTarget.value
					if(count>=1&&money){
						$('input[name=price]').val((money/count).toFixed(2))
					}
				});
				$("input[name=quantity]").on("input",function(e){
				    //获取input输入的值
					var money=$('input[name=amount]').val()
					var count=e.delegateTarget.value
					if(count>=1&&money){
						$('input[name=price]').val((money/count).toFixed(2))
					}
				});
				
				form.on('select(select1)', function (data) {
					let val=$("#select1").val()
					var formattedTime = year + "-" +
					                   (month < 10 ? "0" : "") + month + "-" + 
					                   (day < 10 ? "0" : "") + day
					$('input[name=starttime]').val(formattedTime)
					switch (val){
						case '1':
						    $('input[name=validity_year]').val('3')
						    $('input[name=quantity]').val('20')
							$('input[name=endtime]').val(year+3 + "-" + (month < 10 ? "0" : "") + month + "-" + (day < 10 ? "0" : "") + day)
						    break;
						case '2':
						    $('input[name=validity_year]').val('3')
							$('input[name=quantity]').val('50')
							$('input[name=endtime]').val(year+3 + "-" + (month < 10 ? "0" : "") + month + "-" + (day < 10 ? "0" : "") + day)
						    break;
						case '3':
						    $('input[name=validity_year]').val('5')
							$('input[name=quantity]').val('50')
							$('input[name=endtime]').val(year+5 + "-" + (month < 10 ? "0" : "") + month + "-" + (day < 10 ? "0" : "") + day)
						    break;
						case '4':
						    $('input[name=validity_year]').val('3')
							$('input[name=endtime]').val(year+3 + "-" + (month < 10 ? "0" : "") + month + "-" + (day < 10 ? "0" : "") + day)
						    break;
					}
				});
				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.starttime=_data.starttime+" 00:00:00"
					_data.endtime=_data.endtime+" 23:59:59"
					console.log(_data,'_data000000')
					layer.confirm('确定要提交数据？', function() {
						loading();
						if(_data.id){
							submitdata(server.shop_copartner_update);
						}else{
							delete _data.id
							submitdata(server.shop_copartner_insert);
						}
						
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				};
				if(_data.id){
					initdata();
				}
				function initdata() {
					$.get(server.shop_copartner_detail, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								var data = res.shop_copartner_record
								form.val("test_detail", data.data);
								$('input[name=copartner_memberid]').val(data.data.memberid)
								
								// var unitType = [];
								// unitType = data.data.type.split(",");
								// var unitTypeCheckbox = $(".service_type").children('input');
								
								// for (var j = 0; j < unitType.length; j++) {
								// 	for (var i = 0; i < unitTypeCheckbox.length; i++) {
								// 		if (unitTypeCheckbox[i].value == unitType[j]) {
								// 			unitTypeCheckbox[i].checked = true;
								// 		}
								// 	}
								// }
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				
				window.searchdata = function(type) {
					layer.open({
						type: 2,
						title: '选择',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['80%', '80%'],
						content: 'choose_member.html',
						end: function() {},
						success: function(val) {
							console.log(val,'val111')
						}
					});
				}
			});
		</script>
	</body>

</html>